<?php

namespace Common\Job;

use Common\Event\SendToMqtt;
use Common\Models\Enums\MqttEnums;
use Hyperf\Di\Annotation\Inject;
use Psr\EventDispatcher\EventDispatcherInterface;

class MqttNoticeSdk
{
    /**
     * @Inject
     * @var EventDispatcherInterface
     */
    #[Inject]
    protected EventDispatcherInterface $eventDispatcher;

    public function sendDeviceStatus(int $project_id,array $message): void
    {
        $this->eventDispatcher->dispatch(new SendToMqtt(MqttEnums::device_status.'/'.$project_id, json_encode($message)));
    }

    /**
     * 给订阅消息发送内容
     * @param string $topic
     * @param int $project_id
     * @param array $message
     * @return void
     */
    public function publishMessage(string $topic,int $project_id,array $message)
    {
        $this->eventDispatcher->dispatch(new SendToMqtt($topic.'/'.$project_id, json_encode($message)));
    }
}